package com.hiwan.framework.servlet.tags;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;

import com.hiwan.platform.util.BeanUtils;
import com.hiwan.system.service.dept.DeptService;

/**
 * 
 * Datetime   ： 2013-1-29 下午3:27:58<br>
 * Title      :  DictNameByCodeTag.java<br>
 * Description:  根据字典表的code获取name <br>
 * Copyright  :  Copyright (c) 2013<br>
 * Company    :  HIWAN<br>
 * @author zdm
 *
 */
public class DeptNameByIdTag extends TagSupport {
	
	private static final long serialVersionUID = -7389543849788306702L;
	
	private JspWriter out;
	private String deptId;
	private boolean showId = false;

	@Override
	public int doStartTag() {
		DeptService deptService = BeanUtils.getBean("deptService", DeptService.class);
		try {
			if(StringUtils.isEmpty(deptId)) {
					out.print("");
			} else {
				String deptName = deptService.getDeptName(deptId);
				out = this.pageContext.getOut();
				if(deptName==null||"".equals(deptName)){
					out.print(deptId);
				}else{
					if(showId){
						out.print(deptName+"("+deptId+")");
					}else{
						out.print(deptName);
					}
				}
				
			}
		} catch (Exception e) {
		}
		return Tag.EVAL_PAGE;
	}

	public JspWriter getOut() {
		return out;
	}

	public void setOut(JspWriter out) {
		this.out = out;
	}

	public String getDeptId() {
		return deptId;
	}

	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}

	public boolean isShowId() {
		return showId;
	}

	public void setShowId(boolean showId) {
		this.showId = showId;
	}

	
	
	
}
